<template>
  <div class="detail-summary">
    <div class="summary-rows">
      <div class="summary-rows-item">
        <h4>名录信息</h4>
        <h4>拉丁名：{{detail['种（拉丁名）']}}</h4>
        <p>中文名：{{detail['种（中文名）']}}</p>
        <p>别名：</p>
        <p>分类地位：</p>
        <p>生态类群：{{detail['生态类群']}}</p>
        <p>入侵物种：</p>
        <p>形态特征：{{detail['形态特征描述']}}</p>
        <p>生物学特征：</p>
        <p>分布范围：</p>
        <p>经济和生态影响：</p>
        <p>繁殖方式：</p>
        <p>生境描述：</p>
      </div>
      <div class="summary-rows-item">
        <Amap vid="summary-map" :center="[119.49872, 32.97117]" :markers="mapMarkers" style="height: 400px"/>
      </div>
    </div>

    <el-divider v-if="gridPics && gridPics.length" />

    <swiper class="el-swiper" v-if="gridPics && gridPics.length" :options="swiperOption">
      <swiper-slide v-for="item in gridPics" :key="item.url">
        <div class="el-swiper-item">
          <p>网格编号：{{item.grid}}</p>
          <p>详细地址：{{item.address}}</p>
          <img
            class="swiper-image"
            :src="item.url && item.url.length
            ? `http://36.152.9.59:8090/single_img/?url=${item.url[0]}&dw=300&dh=300` 
            : `http://36.152.9.59:8090/single_img/?url=${item.url}&dw=300&dh=300`"
          />
        </div>
      </swiper-slide>
      <div class="swiper-button-prev" slot="button-prev"></div>
      <div class="swiper-button-next" slot="button-next"></div>
    </swiper>
  </div>
</template>

<script>
import Amap from '@/components/map'
import {isValidJson} from '@/utils'
export default {
  name: "PageSummary",
  props: {
    detail: {
      type: Object,
      default: () => ({})
    },
    invest: {
      type: Array,
      default: () => []
    }
  },
  components: {
    Amap,
  },
  computed: {
    itemId(){
      return this.$route.params.id
    },
    gridPics(){
      return this.invest.map(d => ({
        address: d['小地名'],
        grid: d['调查网格编号'],
        url: isValidJson(d['照片文件名'].replaceAll('\'', '"')) ? JSON.parse(d['照片文件名'].replaceAll('\'', '"')) : null,
      }))
    },
    mapMarkers(){
      return this.invest.map(d => ({
        invest: d,
        position: [d['经度'], d['纬度']]
      }))
    }
  },
  data() {
    return {
      demoMarkers: [
        [118.6943582, 31.9441098],
        [118.5954583, 31.9541097],
        [118.9165584, 31.9641096],
        [118.9276585, 31.9741095],
        [118.9387586, 31.9841094],
        [118.9498587, 31.9941093],
      ],
      pics: [
        { url: require('../../assets/images/detail1.jpg'), grid: 63403740, address: '滨海县防港村' },
        { url: require('../../assets/images/detail1.jpg'), grid: 63403741, address: '滨海县防港村' },
        { url: require('../../assets/images/detail1.jpg'), grid: 63403742, address: '滨海县防港村' },
        { url: require('../../assets/images/detail1.jpg'), grid: 63403743, address: '滨海县防港村' },
        { url: require('../../assets/images/detail1.jpg'), grid: 63403744, address: '滨海县防港村' },
        { url: require('../../assets/images/detail1.jpg'), grid: 63403745, address: '滨海县防港村' },
      ],
      swiperOption: {
        loop: true,
        slidesPerView: 5,
        spaceBetween: 20,
        pagination: {
          el: '.swiper-pagination',
          clickable: true
        },
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        }
      }
    }
  },
  created(){
    // todo: 根据this.$route.params.id获取详情数据
    console.log('Page SearchDetail $route.params.id: >>', this.$route.params.id)
  }
};
</script>

<style lang="scss">
.detail-summary{
  .summary-rows{
    display: flex;
    gap: 30px;
    .summary-rows-item{
      flex: 1;
      & > h4 {
        margin-bottom: 8px;
      }
      & > p{
        line-height: 24px;
      }
    }
  }

  .detail-pic-items{
    display: flex;
    justify-content: space-between;
    gap: 20px;
    .detail-pic-item{
      flex: 1;
      & > p {
        line-height: 30px;
      }
      & > img{
        display: block;
        width: 100%;
        border-radius: 4px;
        box-shadow: 1px 2px 4px rgba(0,0,0,0.1);
      }
    }
  }
}


.el-swiper{
  .el-swiper-item{
    padding: 8px;
    border: 1px solid #ddd;
  }
  p{
    line-height: 2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .swiper-slide{
    .swiper-image{
      display: block;
      width: 100%;
      border-radius: 4px;
      box-shadow: 0 0 4px rgba(0,0,0, .5);
    }
  }
  .swiper-button-prev, .swiper-button-next{
    transform: scale(0.5);
  }
  .swiper-pagination-bullet-active{
    box-shadow: 2px 2px 2px rgba(0,0,0, .5);
    background-color: #fff;
  }
}
</style>